{Core} Workaround empty and multiple scopes provided by old Track 2 SDKs#15806
Merged
{Core} Workaround empty and multiple scopes provided by old Track 2 SDKs#15806
Conversation
Collaborator
|
Core |
fengzhou-msft
approved these changes
Nov 5, 2020
Member
fengzhou-msft
left a comment
There was a problem hiding this comment.
verified with datashare extension.
Juliehzl
reviewed
Nov 6, 2020
| def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument | ||
| logger.debug("MSIAuthenticationWrapper.get_token invoked by Track 2 SDK with scopes=%s", scopes) | ||
| self.resource = scopes_to_resource(scopes) | ||
| resource = _try_scopes_to_resource(scopes) |
Contributor
There was a problem hiding this comment.
If the resource is None, which resource is used to get token then?
Member
Author
There was a problem hiding this comment.
The resource used to create MSIAuthenticationWrapper will be used.
Juliehzl
approved these changes
Nov 6, 2020
arrownj
reviewed
Nov 6, 2020
arrownj
approved these changes
Nov 6, 2020
jsntcy
approved these changes
Nov 6, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refine #15184: {Core} Honor
scopesspecified by Track 2 SDKExpected flow
The current Track 2 SDK client takes
credential_scopeswith only one resource as thescopeswhen callingget_token.https://github.com/Azure/azure-sdk-for-python/blob/27e4203818e227ba2604ff52dcf55ce2293c4c37/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/_configuration.py#L60
Issue 1: Empty scopes
Some old Track 2 SDKs generated before Azure/autorest.python#239 don't maintain
credential_scopesand callsget_tokenwith an emptyscopes.https://github.com/Azure/azure-cli-extensions/blob/db8ea65eb4afa9358de39e06a8c37c85e862a61c/src/datashare/azext_datashare/vendored_sdks/datashare/_configuration.py#L61
https://github.com/Azure/azure-cli-extensions/blob/db8ea65eb4afa9358de39e06a8c37c85e862a61c/src/logic/azext_logic/vendored_sdks/logic/_configuration.py#L61
This causes error:
Issue 2: Multiple scopes
Some old Track 2 SDKs generated before Azure/autorest.python#745 extend default
credential_scopeswith customcredential_scopes. Instead,credential_scopesshould be replaced by customcredential_scopes. Azure/azure-sdk-for-python#12947https://github.com/Azure/azure-cli-extensions/blob/120196e953f7b776fa209f4c49838b5cc7af56b0/src/account/azext_account/vendored_sdks/subscription/_configuration.py#L44-L45
Changes
This PR unifies the fixes for the above 2 issues in one function
_try_scopes_to_resource:Testing Guide
⚠ The workarounds only work for now as
get_tokenis implemented by Azure CLI. After migrating to Azure Identity, these workarounds will fail. The old problematic SDKs MUST be regenerated.